using System;
using System.Collections.Generic;
using System.Linq;
using SkaldRogueLike.Main.DungeonGenerating.DirectionProcessing;

namespace SkaldRogueLike.Main.DungeonGenerating.MapImplementations
{
    public class DungeonCell
    {
        public bool Visited { get; set; }
        public bool IsDeadEnd { get { return _sides.Values.Count(it => it == Side.Wall) == 3; } }
        public bool IsRock { get { return _sides.Values.Count(it => it == Side.Wall) == 4; } }
        public bool IsCorridor { get; set; }
        private readonly Dictionary<Dir, Side> _sides;

        public DungeonCell()
        {
            _sides = new Dictionary<Dir, Side>
                        {
                            {Dir.North, Side.Wall},
                            {Dir.East, Side.Wall},
                            {Dir.South, Side.Wall},
                            {Dir.West, Side.Wall}
                        };
        }

        public Side GetSide(Dir dir)
        {
            return _sides[dir];
        }

        public void SetSide(Dir dir, Side side)
        {
            _sides[dir] = side;
        }

        public Dir GetDeadEndCorridorDir()
        {
            if (!IsDeadEnd)
                throw new ArgumentException("Cell is not dead end");
            return _sides.Keys.Single(it => _sides[it] == Side.Empty);
        }
    }
}